package org.csu.lestore.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.csu.lestore.api.common.CommonResponse;
import org.csu.lestore.api.entity.*;
import org.csu.lestore.api.persistence.*;
import org.csu.lestore.api.service.CatalogService;
import org.csu.lestore.api.util.ImgUtil;
import org.csu.lestore.api.vo.CategoryVO;
import org.csu.lestore.api.vo.ItemVO;
import org.csu.lestore.api.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Service("catalogService")
public class CatalogServiceImpl implements CatalogService {
    @Autowired
    CategoryMapper categoryMapper;
    @Autowired
    ProductMapper productMapper;
    @Autowired
    ItemMapper itemMapper;
    @Autowired
    ImgMapper imgMapper;
    @Autowired
    private FavMapper favMapper;
    @Autowired
    private BrowseMapper browseMapper;

    @Override
    public CommonResponse<IPage<CategoryVO>> getCategoryListInPage(int curPage, int size) {
        IPage<Category> page = new Page<>(curPage,size);
        categoryMapper.selectPage(page,null);

        IPage<CategoryVO> categoryVOPage = new Page<>(curPage,size);
        List<Category> categoryList = page.getRecords();
        List<CategoryVO> categoryVOList = new ArrayList<>();

        if(categoryList!=null){
            for(Category category : categoryList){
                QueryWrapper<Img> imgQueryWrapper = new QueryWrapper<>();
                imgQueryWrapper.eq("img_id",category.getCategoryImg());
                Img img = imgMapper.selectOne(imgQueryWrapper);
                CategoryVO categoryVO = categoryToCategoryVO(category,img);
                categoryVOList.add(categoryVO);
            }
            categoryVOPage.setRecords(categoryVOList);
            categoryVOPage.setPages(page.getPages());
            categoryVOPage.setTotal(page.getTotal());
            return CommonResponse.createForSuccess(categoryVOPage);
        }
        return CommonResponse.createForError("获取category列表失败");
    }

    @Override
    public CommonResponse<CategoryVO> getCategoryById(int categoryId) {
        QueryWrapper<Category> categoryQueryWrapper = new QueryWrapper<>();
        categoryQueryWrapper.eq("category_id",categoryId);

        Category category = categoryMapper.selectOne(categoryQueryWrapper);
        if(category==null){
            return CommonResponse.createForError("根据categoryId获取信息失败");
        }
        QueryWrapper<Img> imgQueryWrapper = new QueryWrapper<>();
        imgQueryWrapper.eq("img_id",category.getCategoryImg());
        Img img = imgMapper.selectOne(imgQueryWrapper);
        CategoryVO categoryVO = categoryToCategoryVO(category,img);
        return CommonResponse.createForSuccess(categoryVO);
    }

    @Override
    public CommonResponse<IPage<ProductVO>> getProductListInPage(int curPage, int size) {
        IPage<Product> page = new Page<>(curPage,size);
        productMapper.selectPage(page,null);

        IPage<ProductVO> productVOPage = new Page<>(curPage,size);
        List<Product> productList = page.getRecords();
        List<ProductVO> productVOList = new ArrayList<>();

        if(productList!=null){
            for(Product product : productList){
                ProductVO productVO = productToProductVO(product);
                productVOList.add(productVO);
            }
            productVOPage.setTotal(page.getTotal());
            productVOPage.setPages(page.getPages());
            productVOPage.setRecords(productVOList);
            return CommonResponse.createForSuccess(productVOPage);
        }
        return CommonResponse.createForError("获取product列表失败");
    }

    @Override
    public CommonResponse<IPage<ProductVO>> getProductListInPageByCategoryId(int curPage, int size,int categoryId) {
        IPage<Product> page = new Page<>(curPage,size);
        QueryWrapper<Product> productQueryWrapper = new QueryWrapper<>();
        productQueryWrapper.eq("category_id",categoryId);
        productMapper.selectPage(page,productQueryWrapper);

        IPage<ProductVO> productVOPage = new Page<>(curPage,size);
        List<Product> productList = page.getRecords();
        List<ProductVO> productVOList = new ArrayList<>();

        if(productList!=null){
            for(Product product : productList){
                ProductVO productVO = productToProductVO(product);
                productVOList.add(productVO);
            }
            productVOPage.setTotal(page.getTotal());
            productVOPage.setPages(page.getPages());
            productVOPage.setRecords(productVOList);
            return CommonResponse.createForSuccess(productVOPage);
        }
        return CommonResponse.createForError("获取product列表失败");
    }

    @Override
    public CommonResponse<ProductVO> getProductById(int productId) {
        QueryWrapper<Product> productQueryWrapper = new QueryWrapper<>();
        productQueryWrapper.eq("product_id",productId);

        Product product = productMapper.selectOne(productQueryWrapper);
        if(product==null){
            return CommonResponse.createForError("根据productId获取信息失败");
        }
        ProductVO productVO = productToProductVO(product);
        return CommonResponse.createForSuccess(productVO);
    }

    @Override
    public CommonResponse<IPage<ProductVO>> getProductByName(int curPage, int size,String name) {
        IPage<Product> page = new Page<>(curPage,size);
        QueryWrapper<Product> productQueryWrapper = new QueryWrapper<>();
        productQueryWrapper.like("product_name",name);
        productMapper.selectPage(page,productQueryWrapper);

        IPage<ProductVO> productVOPage = new Page<>(curPage,size);
        List<Product> productList = page.getRecords();
        List<ProductVO> productVOList = new ArrayList<>();

        if(productList!=null){
            for(Product product : productList){
                ProductVO productVO = productToProductVO(product);
                productVOList.add(productVO);
            }
            productVOPage.setTotal(page.getTotal());
            productVOPage.setPages(page.getPages());
            productVOPage.setRecords(productVOList);
            return CommonResponse.createForSuccess(productVOPage);
        }
        return CommonResponse.createForError("获取product列表失败");
    }

    @Override
    public CommonResponse<IPage<ItemVO>> getItemsInPageByProductId(int curPage, int size,int productId) {
        IPage<Item> itemPage = new Page<>(curPage,size);
        QueryWrapper<Item> itemQueryWrapper = new QueryWrapper<>();
        itemQueryWrapper.eq("product_id",productId);
        itemMapper.selectPage(itemPage,itemQueryWrapper);

        List<Item> itemList = itemPage.getRecords();
        List<ItemVO> itemVOList = new ArrayList<>();
        IPage<ItemVO> itemVOPage = new Page<>(curPage,size);

        if(itemList != null){
            for(Item item : itemList){
                ItemVO itemVO = itemToItemVO(item);
                itemVOList.add(itemVO);
            }
        }
        itemVOPage.setTotal(itemPage.getTotal());
        itemVOPage.setPages(itemPage.getPages());
        itemVOPage.setRecords(itemVOList);
        return CommonResponse.createForSuccess(itemVOPage);
    }

    @Override
    public CommonResponse<ItemVO> getItemByItemId(int itemId) {
        QueryWrapper<Item> itemQueryWrapper = new QueryWrapper<>();
        itemQueryWrapper.eq("item_id",itemId);
        Item item = itemMapper.selectOne(itemQueryWrapper);

        if(item==null){
            return CommonResponse.createForError("根据id获取item信息失败");
        }

        ItemVO itemVO = itemToItemVO(item);
        return CommonResponse.createForSuccess(itemVO);
    }

    @Override
    public CommonResponse<ItemVO> getItemByAttr(int productId, String attr1, String attr2, String attr3) {
        QueryWrapper<Item> itemQueryWrapper = new QueryWrapper<>();
        itemQueryWrapper.eq("product_id",productId);
        itemQueryWrapper.eq("attr1",attr1);
        itemQueryWrapper.eq("attr2",attr2);
        itemQueryWrapper.eq("attr3",attr3);
        Item item = itemMapper.selectOne(itemQueryWrapper);

        if(item==null){
            return CommonResponse.createForError("根据attr获取item信息失败");
        }

        ItemVO itemVO = itemToItemVO(item);
        return CommonResponse.createForSuccess(itemVO);
    }

    @Override
    public CommonResponse<CategoryVO> insertCategory(CategoryVO categoryVO) {

        Category category = new Category();
        category.setCategoryName(categoryVO.getCategoryName());
        if(categoryVO.getImgSrc()!=null){
            Img img = new Img();
            img.setImgSrc(categoryVO.getImgSrc());
            imgMapper.insert(img);
            category.setCategoryImg(img.getImgId());
        }else{
            category.setCategoryImg(-1);
        }
        categoryMapper.insert(category);
        return CommonResponse.createForSuccessMessage("新增category成功");
    }

    @Override
    public CommonResponse<Category> updateCategory(Category category) {
        QueryWrapper<Category> categoryQueryWrapper = new QueryWrapper<>();
        categoryQueryWrapper.eq("category_id",category.getCategoryId());
        categoryMapper.update(category,categoryQueryWrapper);
        return CommonResponse.createForSuccessMessage("修改成功");
    }

    @Override
    public CommonResponse<Category> deleteCategory(int categoryId) {
        QueryWrapper<Category> categoryQueryWrapper = new QueryWrapper<>();
        categoryQueryWrapper.eq("category_id",categoryId);
        Category category = categoryMapper.selectOne(categoryQueryWrapper);

        QueryWrapper<Img> imgQueryWrapper = new QueryWrapper<>();
        imgQueryWrapper.eq("img_id",category.getCategoryImg());
        imgMapper.delete(imgQueryWrapper);

        QueryWrapper<Product> productQueryWrapper = new QueryWrapper<>();
        productQueryWrapper.eq("category_id",categoryId);
        List<Product> productList = productMapper.selectList(productQueryWrapper);
        if(productList != null){
            for(Product product : productList){
                deleteItem(product.getProductId());
            }
        }

        categoryMapper.delete(categoryQueryWrapper);
        return CommonResponse.createForSuccessMessage("删除category成功");
    }

    @Override
    public CommonResponse<Product> insertProduct(Product product) {
        productMapper.insert(product);
        return CommonResponse.createForSuccessMessage("新增product成功");
    }

    @Override
    public CommonResponse<Product> updateProduct(Product product) {
        QueryWrapper<Product> productQueryWrapper = new QueryWrapper<>();
        productQueryWrapper.eq("product_id",product.getProductId());
        productMapper.update(product,productQueryWrapper);
        return CommonResponse.createForSuccessMessage("修改成功");
    }

    @Override
    public CommonResponse<Product> deleteProduct(int productId) {
        QueryWrapper<Item> itemQueryWrapper = new QueryWrapper<>();
        itemQueryWrapper.eq("product_id",productId);
        List<Item> itemList = itemMapper.selectList(itemQueryWrapper);
        if(itemList != null){
            for(Item item : itemList){
                deleteItem(item.getItemId());
            }
        }
        QueryWrapper<Img> imgQueryWrapper = new QueryWrapper<>();
        imgQueryWrapper.eq("product_id",productId);
        imgMapper.delete(imgQueryWrapper);
        QueryWrapper<Product> productQueryWrapper = new QueryWrapper<>();
        productQueryWrapper.eq("product_id",productId);
        productMapper.delete(productQueryWrapper);
        return CommonResponse.createForSuccessMessage("删除product成功");
    }

    @Override
    public CommonResponse<ItemVO> insertItem(ItemVO itemVO) {
        Item item = new Item();
        item.setProductId(itemVO.getProductId());
        item.setStock(itemVO.getStock());
        item.setPrice(itemVO.getPrice());
        item.setAttr1(itemVO.getAttr1());
        item.setAttr2(itemVO.getAttr2());
        item.setAttr3(itemVO.getAttr3());
        if(itemVO.getImgSrc()!=null){
            Img img = new Img();
            img.setImgSrc(itemVO.getImgSrc());
            imgMapper.insert(img);
            item.setItemImg(img.getImgId());
        }else{
            item.setItemImg(-1);
        }
        itemMapper.insert(item);
        return CommonResponse.createForSuccessMessage("新增item成功");
    }

    @Override
    public CommonResponse<Item> updateItem(Item item) {
        QueryWrapper<Item> itemQueryWrapper = new QueryWrapper<>();
        itemQueryWrapper.eq("item_id",item.getItemId());
        itemMapper.update(item,itemQueryWrapper);
        return CommonResponse.createForSuccessMessage("修改成功");
    }

    @Override
    public CommonResponse<Item> deleteItem(int itemId) {
        QueryWrapper<Item> itemQueryWrapper = new QueryWrapper<>();
        itemQueryWrapper.eq("item_id",itemId);
        Item item = itemMapper.selectOne(itemQueryWrapper);

        QueryWrapper<Img> imgQueryWrapper = new QueryWrapper<>();
        imgQueryWrapper.eq("img_id",item.getItemImg());
        imgMapper.delete(imgQueryWrapper);

        itemMapper.delete(itemQueryWrapper);
        return CommonResponse.createForSuccessMessage("删除item成功");
    }

    @Override
    public CommonResponse<Img> setProductImg(Img img) {
        QueryWrapper<Product> productQueryWrapper = new QueryWrapper<>();
        productQueryWrapper.eq("product_id",img.getProductId());
        Product existProduct = productMapper.selectOne(productQueryWrapper);
        if(existProduct!=null){
            imgMapper.insert(img);
            return CommonResponse.createForSuccessMessage("插入img成功");
        }
        else{
            return CommonResponse.createForError("product不存在");
        }
    }

    @Override
    public CommonResponse<CategoryVO> setCategoryImg(int categoryId, String imgSrc) {
        QueryWrapper<Category> categoryQueryWrapper = new QueryWrapper<>();
        categoryQueryWrapper.eq("category_id",categoryId);
        Category category = categoryMapper.selectOne(categoryQueryWrapper);

        Img img = new Img();
        img.setImgSrc(imgSrc);
        if(category.getCategoryImg()!=-1){
            img.setImgId(category.getCategoryImg());
            QueryWrapper<Img> imgQueryWrapper = new QueryWrapper<>();
            imgQueryWrapper.eq("img_id",img.getImgId());
            imgMapper.update(img,imgQueryWrapper);
        }else{
            imgMapper.insert(img);
            category.setCategoryImg(img.getImgId());
            updateCategory(category);
        }

        return CommonResponse.createForSuccess(categoryToCategoryVO(category,img));
    }

    @Override
    public CommonResponse<ItemVO> setItemImg(int itemId, String imgSrc) {
        QueryWrapper<Item> itemQueryWrapper = new QueryWrapper<>();
        itemQueryWrapper.eq("item_id",itemId);
        Item item = itemMapper.selectOne(itemQueryWrapper);

        Img img = new Img();
        img.setImgSrc(imgSrc);
        if(item.getItemImg()!=-1){
            img.setImgId(item.getItemImg());
            QueryWrapper<Img> imgQueryWrapper = new QueryWrapper<>();
            imgQueryWrapper.eq("img_id",img.getImgId());
            imgMapper.update(img,imgQueryWrapper);
        }else{
            imgMapper.insert(img);
            item.setItemImg(img.getImgId());
            updateItem(item);
        }

        return CommonResponse.createForSuccess(itemToItemVO(item));
    }

    @Override
    public CommonResponse<Fav> setFavProduct(Fav fav) {
        QueryWrapper<Fav> favQueryWrapper = new QueryWrapper<>();
        favQueryWrapper.eq("user_id",fav.getUserId());
        favQueryWrapper.eq("product_id",fav.getProductId());
        Fav existFav = favMapper.selectOne(favQueryWrapper);
        if(existFav != null){
            return CommonResponse.createForError("该商品已添加收藏");
        }else{
            favMapper.insert(fav);
        }
        return CommonResponse.createForSuccessMessage("添加收藏成功");
    }

    @Override
    public CommonResponse<Fav> deleteFavProduct(Fav fav) {
        QueryWrapper<Fav> favQueryWrapper = new QueryWrapper<>();
        favQueryWrapper.eq("user_id",fav.getUserId());
        favQueryWrapper.eq("product_id",fav.getProductId());
        favMapper.delete(favQueryWrapper);
        return CommonResponse.createForSuccessMessage("取消收藏成功");
    }

    @Override
    public CommonResponse<Fav> getFavProduct(int userId,int productId) {
        QueryWrapper<Fav> favQueryWrapper = new QueryWrapper<>();
        favQueryWrapper.eq("user_id",userId);
        favQueryWrapper.eq("product_id",productId);

        return CommonResponse.createForSuccess(favMapper.selectOne(favQueryWrapper));
    }

    @Override
    public CommonResponse<IPage<ProductVO>> getFavProductListInPageByUserIdAndKeyword(int curPage, int size, int userId, String keyword) {
        IPage<Fav> favPage = new Page<>(curPage,size);
        QueryWrapper<Fav> favQueryWrapper = new QueryWrapper<>();
        favQueryWrapper.eq("user_id",userId);
        favMapper.selectPage(favPage,favQueryWrapper);

        List<Fav> favList = favPage.getRecords();
        List<ProductVO> productVOList = new ArrayList<>();
        IPage<ProductVO> productVOPage = new Page<>(curPage,size);
        int count = 0;
        if(favList!=null){
            for(Fav fav : favList){
                QueryWrapper<Product> productQueryWrapper = new QueryWrapper<>();
                productQueryWrapper.eq("product_id",fav.getProductId());
                productQueryWrapper.like("product_name",keyword);
                Product product = productMapper.selectOne(productQueryWrapper);
                if(product!=null){
                    ProductVO productVO = productToProductVO(product);
                    productVOList.add(productVO);
                    count++;
                }
            }
        }
        productVOPage.setTotal(count);
        //productVOPage.setPages(favPage.getPages());
        productVOPage.setRecords(productVOList);

        return CommonResponse.createForSuccess(productVOPage);
    }

    @Override
    public CommonResponse<IPage<ProductVO>> getFavProductListInPageByUserId(int curPage, int size,int userId) {
        IPage<Fav> favPage = new Page<>(curPage,size);
        QueryWrapper<Fav> favQueryWrapper = new QueryWrapper<>();
        favQueryWrapper.eq("user_id",userId);
        favMapper.selectPage(favPage,favQueryWrapper);

        List<Fav> favList = favPage.getRecords();
        List<ProductVO> productVOList = new ArrayList<>();
        IPage<ProductVO> productVOPage = new Page<>(curPage,size);
        if(favList!=null){
            for(Fav fav : favList){
                QueryWrapper<Product> productQueryWrapper = new QueryWrapper<>();
                productQueryWrapper.eq("product_id",fav.getProductId());
                Product product = productMapper.selectOne(productQueryWrapper);
                ProductVO productVO = productToProductVO(product);
                productVOList.add(productVO);
            }
        }
        productVOPage.setTotal(favPage.getTotal());
        productVOPage.setPages(favPage.getPages());
        productVOPage.setRecords(productVOList);

        return CommonResponse.createForSuccess(productVOPage);
    }

    @Override
    public CommonResponse<Browse> insertBrowseRecord(int userId, int productId) {
        QueryWrapper<Browse> browseQueryWrapper = new QueryWrapper<>();
        browseQueryWrapper.eq("user_id",userId);
        browseQueryWrapper.eq("product_id",productId);
        Browse existBrowse = browseMapper.selectOne(browseQueryWrapper);
        if(existBrowse!=null){
            deleteBrowseRecord(userId,productId);
        }
        Browse newbrowse = new Browse();
        newbrowse.setUserId(userId);
        newbrowse.setProductId(productId);
        browseMapper.insert(newbrowse);
        return null;
    }

    @Override
    public CommonResponse<Browse> deleteBrowseRecord(int userId, int productId) {
        QueryWrapper<Browse> browseQueryWrapper = new QueryWrapper<>();
        browseQueryWrapper.eq("user_id",userId);
        browseQueryWrapper.eq("product_id",productId);
        browseMapper.delete(browseQueryWrapper);
        return null;
    }

    @Override
    public CommonResponse<Browse> deleteAllBrowseRecordsByUserId(int userId) {
        QueryWrapper<Browse> browseQueryWrapper = new QueryWrapper<>();
        browseQueryWrapper.eq("user_id",userId);
        browseMapper.delete(browseQueryWrapper);
        return null;
    }

    @Override
    public CommonResponse<IPage<ProductVO>> getAllBrowseRecordsByUserId(int curPage, int size,int userId) {
        IPage<Browse> browsePage = new Page<>(curPage,size);
        QueryWrapper<Browse> browseQueryWrapper = new QueryWrapper<>();
        browseQueryWrapper.eq("user_id",userId);
        browseMapper.selectPage(browsePage,browseQueryWrapper);

        List<Browse> browseList = browsePage.getRecords();
        List<ProductVO> productVOList = new ArrayList<>();
        IPage<ProductVO> productVOPage = new Page<>(curPage,size);
        if(browseList!=null){
            for(Browse browse : browseList){
                QueryWrapper<Product> productQueryWrapper = new QueryWrapper<>();
                productQueryWrapper.eq("product_id",browse.getProductId());
                Product product = productMapper.selectOne(productQueryWrapper);
                ProductVO productVO = productToProductVO(product);
                productVOList.add(productVO);
            }
        }
        productVOPage.setTotal(browsePage.getTotal());
        productVOPage.setPages(browsePage.getPages());
        productVOPage.setRecords(productVOList);

        return CommonResponse.createForSuccess(productVOPage);
    }

    private ItemVO itemToItemVO(Item item){
        ItemVO itemVO = new ItemVO();

        itemVO.setItemId(item.getItemId());
        itemVO.setProductId(item.getProductId());
        itemVO.setStock(item.getStock());
        itemVO.setPrice(item.getPrice());
        itemVO.setAttr1(item.getAttr1());
        itemVO.setAttr2(item.getAttr2());
        itemVO.setAttr3(item.getAttr3());
        itemVO.setItemImg(item.getItemImg());

        QueryWrapper<Product> productQueryWrapper = new QueryWrapper<>();
        productQueryWrapper.eq("product_id",item.getProductId());
        Product product = productMapper.selectOne(productQueryWrapper);

        if(product!=null){
            itemVO.setCategoryId(product.getCategoryId());
            itemVO.setProductName(product.getProductName());
            itemVO.setProductDescn(product.getProductDescn());
            itemVO.setBussnessId(product.getUserId());
        }

        QueryWrapper<Img> imgQueryWrapper = new QueryWrapper<>();
        imgQueryWrapper.eq("img_id",item.getItemImg());
        Img img = imgMapper.selectOne(imgQueryWrapper);

        if(img!=null){
            itemVO.setImgSrc(ImgUtil.getImageBaseSrc(img.getImgSrc(),"item"));
        }else{
            itemVO.setItemImg(-1);
        }

        return itemVO;
    }

    private ProductVO productToProductVO(Product product){
        ProductVO productVO = new ProductVO();

        productVO.setProductId(product.getProductId());
        productVO.setCategoryId(product.getCategoryId());
        productVO.setProductName(product.getProductName());
        productVO.setProductDescn(product.getProductDescn());
        productVO.setUserId(product.getUserId());

        QueryWrapper<Img> imgQueryWrapper = new QueryWrapper<>();
        imgQueryWrapper.eq("product_id",product.getProductId());
        List<Img> imgList = imgMapper.selectList(imgQueryWrapper);
        if(imgList!=null){
            for(Img img : imgList){
                img.setImgSrc(ImgUtil.getImageBaseSrc(img.getImgSrc(),"product"));
            }
        }
        productVO.setImgList(imgList);

        QueryWrapper<Item> itemQueryWrapper = new QueryWrapper<>();
        itemQueryWrapper.eq("product_id",product.getProductId());
        List<Item> itemList = itemMapper.selectList(itemQueryWrapper);
        List<ItemVO> itemVOList = new ArrayList<>();
        if(itemList!=null){
            for(Item item : itemList){
                ItemVO itemVO = itemToItemVO(item);
                itemVOList.add(itemVO);
            }
        }
        productVO.setItemVOList(itemVOList);

        BigDecimal maxPrice = null;
        if(itemList!=null){
            for(Item item : itemList){
                if(maxPrice==null||maxPrice.compareTo(item.getPrice())<0){
                    maxPrice = item.getPrice();
                }
            }
            productVO.setMaxPrice(maxPrice);
        }

        BigDecimal minPrice = null;
        if(itemList!=null){
            for(Item item : itemList){
                if(minPrice==null||minPrice.compareTo(item.getPrice())>0){
                    minPrice = item.getPrice();
                }
            }
            productVO.setMinPrice(minPrice);
        }

        return productVO;
    }

    private CategoryVO categoryToCategoryVO(Category category,Img img){
        CategoryVO categoryVO = new CategoryVO();

        categoryVO.setCategoryId(category.getCategoryId());
        categoryVO.setCategoryName(category.getCategoryName());
        categoryVO.setCategoryImg(category.getCategoryImg());
        if (img!=null){
            categoryVO.setImgSrc(ImgUtil.getImageBaseSrc(img.getImgSrc(),"category"));
        }else{
            categoryVO.setCategoryImg(-1);
        }


        return categoryVO;
    }
}
